<?php
require("page_start.php");

$msg = $_GET["retorno"];

print("
<p><p>
<table align=\"center\" width=\"75%\"><tr><td>
");

if ( $msg == 0 ) {
	print("$msg");
}

print("
<form action=\"dhcp_save_restart.php\">
<center><input type=\"submit\" value=\"Salvar e Reiniciar DHCPD\"></center>
</form>


<fieldset><legend>Servidor DHCP</legend>
<form action=\"dhcp_add_net.php\" method=\"POST\">
<table align=\"center\">
<tr><td>Dom&iacute;nio:</td><td><input type=\"text\" name=\"domain\" ></td></tr>
<tr><td>Rede:</td><td><input type=\"text\" name=\"net\" ></td></tr>
<tr><td>M&aacute;scara:</td><td><input type=\"text\" name=\"netmask\" </td></tr>
<tr><td>IP inicial:</td><td><input type=\"text\" name=\"ip1\" ></td></tr>
<tr><td>IP final:</td><td><input type=\"text\" name=\"ip2\" ></td></tr>
<tr><td>Gateway:</td><td><input type=\"text\" name=\"gw\" ></td></tr>
<tr><td>DNS prim&aacute;rio:</td><td><input type=\"text\" name=\"dns1\" ></td></tr>
<tr><td>DNS Secund&aacute;rio:</td><td><input type=\"text\" name=\"dns2\" ></td></tr>
</table>
<p>
<center><input type=\"submit\" value=\"ADICIONAR\"></center>
</form>
</center>
</fieldset>
");

$sqlite_handle = sqlite_open('dhcpd.sqlite');
$cellcolor='background-color: rgb(192, 201, 157)';

print("<p><p>");

print("<center><fieldset><legend>Redes Dhcp</legend>\n<table border=\"2\">\n");
print("\t<tr><td align=\"center\">Nome</td><td align=\"center\">Rede</td><td align=\"center\">M&aacute;scara</td><td align=\"center\">In&iacute;cio</td><td align=\"center\">Fim</td><td align=\"center\">Gateway</td><td align=\"center\">Dns1</td><td align=\"center\" colspan=\"2\">Dns2</td></tr>\n");


$dhcpnets = sqlite_array_query( $sqlite_handle , "SELECT * FROM redes");

foreach ( $dhcpnets as $dhcpNET ) {
	print("\t<tr><td style=\" $cellcolor ;\">$dhcpNET[domain]</td><td style=\" $cellcolor ;\">$dhcpNET[net]</td><td style=\" $cellcolor ;\">$dhcpNET[netmask]</td><td style=\" $cellcolor ;\">$dhcpNET[ipstart]</td><td style=\" $cellcolor ;\">$dhcpNET[ipstop]</td><td style=\" $cellcolor ;\">$dhcpNET[gw]</td><td style=\" $cellcolor ;\">$dhcpNET[dns1]</td><td style=\" $cellcolor ;\">$dhcpNET[dns2]</td><td style=\" $cellcolor ;\"><a href=dhcp_del_net.php?domain=$dhcpNET[domain]>DEL</a></td style=\" $cellcolor ;\"> </tr>\n");
}

print ("</table>\n</fieldset></center>");


print("
<p><p>

<fieldset><legend>Fixar IP Dinâmico</legend>
<form action=\"dhcp_add_fix_ip.php\" method=\"POST\">
<center>
<table>
<tr><td>HOSTNAME:</td><td><input type=\"text\" name=\"fixed_ip_hostname\"></td></tr>
<tr><td>IP FIXADO:</td><td><input type=\"text\" name=\"fixed_ip\"></td></tr>
<tr><td>MAC ADDR:</td><td><input type=\"text\" name=\"fixed_ip_mac\"></td></tr>
<tr><td>COMENT&Aacute;RIO:</td><td><input type=\"text\" name=\"fixed_ip_com\"></td></tr>
</table>
<p>
<input type=\"submit\" value=\"ADICIONAR\">
</form>
</center>
</fieldset>

<p><p>

<fieldset><legend>IP's Fixados Dinamicamente</legend>
");


$resultado = sqlite_array_query($sqlite_handle , "SELECT hostname,ip,mac,comentario FROM dhcpd ORDER BY ip;"); 

print("<center>\n\t<table border=\"2\">");
print("<tr><td align=\"center\">Hostname</td><td align=\"center\">IP</td><td align=\"center\">MAC</td><td colspan=\"2\" align=\"center\">Coment&aacute;rio</td></tr>");


foreach ( $resultado as $linha ) {
	print("\n\t\t<tr style=\" $cellcolor ;\"><td>" . $linha["hostname"] . "</td><td>" . $linha["ip"] . "</td><td>" . $linha["mac"] . "</td><td>" . $linha["comentario"] . "</td><td align=\"center\"><a href=dhcp_del_fix_ip.php?hostname=" . $linha["hostname"] . ">DEL</a></td></tr>\n");
};

sqlite_close($sqlite_handle);

print("\t</table>\n</center>");
print("\n</fieldset>\n</tr></td></table>");
require("page_end.php");
?>